using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using Dto.ApiResponses.MemberResponses;

namespace Client.Converters
{
    [ValueConversion(typeof(MemberDetailResponse), typeof(FlowDocument))]
    public class MemberConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var response = value as MemberDetailResponse;
            if (response == null) return null;
            var member = response.Detail;
            var paragraph = new Paragraph { FontFamily = new FontFamily("Times New Roman"), FontSize = 14 };
            paragraph.Inlines.Add(new Bold(new Run(member.Name)));
            paragraph.Inlines.Add(new LineBreak());
            paragraph.Inlines.Add(new Run(string.Format("{0}", member.Address)));
            paragraph.Inlines.Add(new LineBreak());
            paragraph.Inlines.Add(new Run(string.Format("Mobile: {0}", member.Mobile)));
            paragraph.Inlines.Add(new LineBreak());
            paragraph.Inlines.Add(new Run(string.Format("Privilege: {0}", member.RoleName)));
            paragraph.Inlines.Add(new LineBreak());
            var flowDocument = new FlowDocument { PagePadding = new Thickness(0) };
            flowDocument.Blocks.Add(paragraph);
            return flowDocument;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new Exception("ConvertBack can not be called.");
        }
    }
}